param( [string]$SourceDir
     , [switch]$Quiet
     , [switch]$Passthrough
     , [switch]$Recurse
     )

begin
{
    $files = @()
    if ( $SourceDir -ne '' )
    {
	   $SourcePath = (Get-Item $SourceDir).FullName
       $files = Get-ChildItem $SourcePath -Recurse:$Recurse
    }
}

process
{
    if ($_ -is [system.io.fileinfo])
    {
        $files += $_
    }
}

end
{

    if (! $Quiet )
    {
        write-host "Processing $($files.count) files"
    }

	$GroupedDuplicates = 
        $files | 
        Set-Manifest  | 
        Group-Object -property Checksum | 
        ?{$_.Count -gt 1} 
    
    $Result = new-object "System.Collections.ArrayList"
    foreach ($GroupedDuplicate in $GroupedDuplicates)
    {
        if (! $Quiet )
        {
            Write-Host ""
            Write-Host "File Path"
            Write-Host "------------------------------------------------------"
        }
        
        $FileNames = @()
        foreach ($File in $GroupedDuplicate.Group)
        {
            if (! $Quiet )
            {
                Write-Host $File.RelativePath
            }
            
            $FileNames += $File.RelativePath
        }
        [void] $Result.Add($FileNames)
    }
    if ( $Passthrough )
    {
        $Result.ToArray()
    }
}